#include "sal.h"
#include "api/include/ctc_api.h"
#include "api/include/ctcs_api.h"
#include "ctc_app.h"

extern int32 userinit(uint8 ctc_shell_mode, uint8 ctcs_api_en, void* p_init_config);
extern int32 ctc_cli_start(int32 ctc_shell_mode);
extern ctc_app_master_t g_ctc_app_master;

#if !defined SDK_IN_VXWORKS && !defined _SAL_LINUX_KM
void
ctc_app_main_usage(void)
{
    CTC_APP_DBG_OUT(CTC_DEBUG_LEVEL_DUMP, "Usage: ctcsdk [OPTIONS...]\r\n");
    CTC_APP_DBG_OUT(CTC_DEBUG_LEVEL_DUMP, "Options:\n");
    CTC_APP_DBG_OUT(CTC_DEBUG_LEVEL_DUMP, "  cli       CLI mode\n");
    CTC_APP_DBG_OUT(CTC_DEBUG_LEVEL_DUMP, "  ctcs      CTCS mode\n");
    CTC_APP_DBG_OUT(CTC_DEBUG_LEVEL_DUMP, "  warmboot  Warm boot mode\n");
    CTC_APP_DBG_OUT(CTC_DEBUG_LEVEL_DUMP, "  reloading Warm boot reloading process\n");
    return;
}

int32
main(const int argc,const char* argv[])
{
    int32 ret = 0;
    uint8 loop = 0;
    uint8 ctc_shell_mode = 1;
    uint8 ctcs_api_en = 1;

    while(++loop < argc)
    {
        if (!sal_strcmp(argv[loop], "-h"))
        {
            ctc_app_main_usage();
            return 0;
        }

        if (!sal_strcmp(argv[loop], "cli"))
        {
            ctc_shell_mode =  0;
        }
        else if (!sal_strcmp(argv[loop], "ctc"))
        {
            ctcs_api_en = 0;
        }
        else if (!sal_strcmp(argv[loop], "wb") || !sal_strcmp(argv[loop], "warmboot"))
        {
            g_ctc_app_master.wb_enable = 1;
            g_ctc_app_master.wb_mode = 1;   //default is dm mode
        }
        else if (!sal_strcmp(argv[loop], "-db"))
        {
            g_ctc_app_master.wb_mode = 0;
        }
        else if (!sal_strcmp(argv[loop], "reloading"))
        {
            g_ctc_app_master.wb_reloading = 1;
        }
    }

    ret = userinit(ctc_shell_mode, ctcs_api_en, NULL);
    if (0 != ret)
    {
        return ret;
    }
    ret = ctc_cli_start(ctc_shell_mode);

    return ret;
}
#endif

